﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using LowLevelGraphics.Filter;

namespace ImageRecognition2.Forms
{
    /// <summary>
    /// Antivignetting
    /// </summary>
    public partial class FormAntivignetting : FormFilter
    {
        protected Antivignetting m_AntiVignetting = new Antivignetting();

        /// <summary>
        /// Initializes a new instance of the <see cref="FormAntivignetting"/> class.
        /// </summary>
        public FormAntivignetting()
        {
            InitializeComponent();
            this.Shown += new EventHandler(FormAntivignetting_Shown);
            this.pictureBox1.BackgroundImageLayout = ImageLayout.Zoom;
            this.tbAmount.TextChanged += new EventHandler(valueChanged);
            this.tbRadius.TextChanged += new EventHandler(valueChanged);
        }

        void valueChanged(object sender, EventArgs e)
        {
            Bitmap bitmap = (Bitmap)m_ImageOriginal.Clone();
            Antivignetting(bitmap);
            pictureBox1.BackgroundImage = bitmap;
        }

        /// <summary>
        /// Shown
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void FormAntivignetting_Shown(object sender, EventArgs e)
        {
            m_ImageOriginal = MainFormSingleton.ActivePictureBox.BackgroundImage;
            this.pictureBox1.BackgroundImage = m_ImageOriginal;
        }

        /// <summary>
        /// Gets or sets the radius.
        /// </summary>
        /// <value>The radius.</value>
        public Double Radius
        {
            get { return Convert.ToDouble(tbRadius.Text); }
            set { tbRadius.Text = value.ToString(); }
        }

        /// <summary>
        /// Gets or sets the power.
        /// </summary>
        /// <value>The power.</value>
        public Double Power
        {
            get { return Convert.ToDouble(tbRadius.Text); }
            set { tbRadius.Text = value.ToString(); }
        }

        /// <summary>
        /// Gets or sets the density.
        /// </summary>
        /// <value>The density.</value>
        public double Density
        {
            get { return Convert.ToDouble(tbAmount.Text); }
            set { tbAmount.Text = value.ToString(); }
        }

        /// <summary>
        /// Antivignetting
        /// </summary>
        /// <param name="bitmap"></param>
        private void Antivignetting(Bitmap bitmap)
        {
            m_AntiVignetting.Radius = Radius;
            m_AntiVignetting.Density = Density;
            m_AntiVignetting.Power = Power;
            m_AntiVignetting.Execute(bitmap).Dispose();
        }

        /// <summary>
        /// ok click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbOK_Click(object sender, EventArgs e)
        {
            Image image = (Image)m_ImageOriginal.Clone();
            Antivignetting((Bitmap)image);
            MainFormSingleton.ActivePictureBox.BackgroundImage = image;
        }
    }
}
